package com.umanji.generic.entity;

import java.io.Serializable;
import javax.persistence.MappedSuperclass;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

/**
 *
 * @param <PK>
 * @author Daniel Walker <plaxdan@gmail.com>
 */
@MappedSuperclass
public abstract class AbstractEntity<E extends AbstractEntity<?,?>, PK extends Comparable<PK> & Serializable> implements Entity<E, PK> {

    private Long version;

    @Override
    public Long getVersion() {
        return version;
    }

    @Override
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AbstractEntity<E, PK> other = (AbstractEntity<E, PK>)obj;
        if (this.getUuid() != other.getUuid() && (this.getUuid() == null || !this.getUuid().equals(other.getUuid()))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.getUuid() != null ? this.getUuid().hashCode() : 0);
        hash = 97 * hash + (this.version != null ? this.version.hashCode() : 0);
        return hash;
    }

    @Override
    public int compareTo(E o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }
}

